#include "Blok.h"


Blok::Blok()
{
	this->init(0.0f, 0.0f, 0.0f);

#ifdef FLIKKER
	srand(time(NULL));
#endif

}
Blok::Blok(GLfloat x, GLfloat y, GLfloat z)
{
	this->init(x, y, z);
}
Blok::Blok(Vector *pos)
{
	this->init(pos->getX(), pos->getY(), pos->getZ());
}
void Blok::setKleur(float r, float g, float b)
{
	this->r = r;
	this->g = g;
	this->b = b;
}
void Blok::init(float x, float y, float z)
{
	this->fX = x;
	this->fY = y;
	this->fZ = z;
	this->fSize = 1.0f;
	this->iAttachedTo = 0;
}
void Blok::setSize(float size)
{
	this->fSize = size;
}

void Blok::attachTo(unsigned short int to, unsigned short int attachMode)
{
	this->iAttachedTo = to;
	this->iAttachMode = attachMode;
}

void Blok::setPos(float x, float y, float z)
{
	this->fX = x;
	this->fY = y;
	this->fZ = z;
}

void Blok::draw()
{


	// front
	glColor3f(r, g, b); // green
	glVertex3f(fX - fSize, fY - fSize, fZ +	fSize); // bl
	glVertex3f(fX - fSize, fY + fSize, fZ +	fSize); // tl
	glVertex3f(fX + fSize, fY + fSize, fZ +	fSize); // tr
	glVertex3f(fX + fSize, fY - fSize, fZ + fSize); // br

	// top
	glColor3f(r-0.1f, g-0.1f, b-0.1f); // red
	glVertex3f(fX - fSize, fY + fSize, fZ + fSize);
	glVertex3f(fX - fSize, fY + fSize, fZ - fSize);
	glVertex3f(fX + fSize, fY + fSize, fZ - fSize);
	glVertex3f(fX + fSize, fY + fSize, fZ + fSize);

	// right
	glColor3f(0.3f, 0.3f, 0.3f); // blue
	glVertex3f(fX + fSize, fY + fSize, fZ + fSize);
	glVertex3f(fX + fSize, fY + fSize, fZ - fSize);
	glVertex3f(fX + fSize, fY - fSize, fZ - fSize);
	glVertex3f(fX + fSize, fY - fSize, fZ + fSize);

	// left
	glColor3f(0.3f, 0.3f, 0.3f);
	glVertex3f(fX - fSize, fY + fSize, fZ + fSize);
	glVertex3f(fX - fSize, fY + fSize, fZ - fSize);
	glVertex3f(fX - fSize, fY - fSize, fZ - fSize);
	glVertex3f(fX - fSize, fY - fSize, fZ + fSize);

	// bottom
	glColor3f(r, g, b); // OK
	glVertex3f(fX - fSize, fY - fSize, fZ +	fSize);
	glVertex3f(fX - fSize, fY - fSize, fZ - fSize);
	glVertex3f(fX + fSize, fY - fSize, fZ - fSize);
	glVertex3f(fX + fSize, fY - fSize, fZ + fSize);

	// back
	glColor3f(r, g, b); // pink
	glVertex3f(fX - fSize, fY - fSize, fZ -	fSize); 
	glVertex3f(fX - fSize, fY + fSize, fZ -	fSize); 
	glVertex3f(fX + fSize, fY + fSize, fZ -	fSize); 
	glVertex3f(fX + fSize, fY - fSize, fZ - fSize); 


}